package com.yimingkeji.mybatis.rest;

import com.yimingkeji.mybatis.entity.User;
import com.yimingkeji.mybatis.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Describe:
 * @Auther: zhenlong.yang
 * @Date: 2018/12/14 13:27
 */
@RestController
public class UserController1 {

    @Autowired private UserMapper userMapper;

    @GetMapping("user")
    public List<User> list(){
        return userMapper.findAll();
    }

    @GetMapping("user/{id}")
    public User one(@PathVariable int id){
        return userMapper.findOne(id);
    }

    @PostMapping("user")
    public int add(@RequestBody User user){
        return userMapper.add(user);
    }


    @PutMapping("user")
    public int update(@RequestBody User user){
        return userMapper.update(user);
    }

    @DeleteMapping("user/{id}")
    public int del(@PathVariable int id){
        return userMapper.delete(id);
    }
}
